package com.kuaifawu.lwnlawyerclient.Adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.kuaifawu.lwnlawyerclient.Model.LWNModel_message;
import com.kuaifawu.lwnlawyerclient.Model.LWNModel_messageSystem;
import com.kuaifawu.lwnlawyerclient.R;
import com.lidroid.xutils.BitmapUtils;

import java.util.List;

/**
 * Created by zhangminglei on 15/2/3.
 */
public class LWNAdapter_messageSystem extends ArrayAdapter {

    private LayoutInflater mInflater;
    private List<LWNModel_messageSystem> mItems;
    private Context context_this;

    public LWNAdapter_messageSystem(Context context, int resource, List objects) {
        super(context, resource, objects);
        context_this = context;
        this.mInflater = LayoutInflater.from(context);
        this.mItems = objects;
    }

    @Override
    public int getCount() {
        return mItems.size();
    }

    @Override
    public LWNModel_messageSystem getItem(int position) {
        return mItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LWNModel_messageSystem item = getItem(position);
        int unread = Integer.parseInt(item.getIsunread());
        View_content view_content = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_messagesystem,null);
            view_content = new View_content();
            view_content.item_title = (TextView) convertView.findViewById(R.id.message_systemTitle);
            view_content.item_content = (TextView) convertView.findViewById(R.id.system_textContent);
            view_content.item_time = (TextView) convertView.findViewById(R.id.system_time);
            view_content.item_img = (ImageView) convertView.findViewById(R.id.system_imageContent);
            view_content.system_newmessage=(ImageView) convertView.findViewById(R.id.system_newmessage);
            convertView.setTag(R.layout.item_messagesystem, view_content);
        } else {
            view_content = (View_content) convertView.getTag(R.layout.item_messagesystem);
            if (view_content == null) {
                view_content = new View_content();
                view_content.item_title = (TextView) convertView.findViewById(R.id.message_systemTitle);
                view_content.item_content = (TextView) convertView.findViewById(R.id.system_textContent);
                view_content.item_time = (TextView) convertView.findViewById(R.id.system_time);
                view_content.item_img = (ImageView) convertView.findViewById(R.id.system_imageContent);
                view_content.system_newmessage=(ImageView) convertView.findViewById(R.id.system_newmessage);
                convertView.setTag(R.layout.item_messagesystem, view_content);
            }
        }

        //设置数据
        view_content.item_title.setText(item.getTitle());
        view_content.item_content.setText(item.getContent());
        view_content.item_time.setText(item.getTime());
        if (unread == 0) {
            view_content.item_title.setTextColor(Color.rgb(169, 169, 169));
            view_content.item_content.setTextColor(Color.rgb(169, 169, 169));
            view_content.system_newmessage.setVisibility(View.INVISIBLE);
        } else {
            view_content.item_title.setTextColor(Color.rgb(121, 121, 121));
            view_content.item_content.setTextColor(Color.rgb(121, 121, 121));
            view_content.system_newmessage.setVisibility(View.VISIBLE);
        }

        BitmapUtils bitmapUtils = new BitmapUtils(context_this);
        String imaeurl=item.getContentimg();
        bitmapUtils.display(view_content.item_img, item.getContentimg());

        return convertView;
    }

    class View_content {
        private TextView item_title;
        private ImageView item_img;
        private TextView item_content;
        private TextView item_time;
        private ImageView system_newmessage;
    }

}
